$(document).ready(function() {	
	$("#frmEduAndWorking").validate({
		errorClass		: 'errorMessage',
		errorElement	: 'span',
		onfocusout		: false,
		onkeyup			: false,
		rules: {
			phschool: {
				requiredField 		: true,
				minlength			: 5
			},
			phscountry: {
				requiredHsCountry	: true
			},
			phsprovince: {
				requiredHsProvince	: true
			},
			phsaddr: {
				requiredHsAddr		: true,
				minlength			: 5
			},
			pcollege: {
				minlength			: 5
			},
			pccountry: {
				requiredCCountry	: true
			},
			pcprovince: {
				requiredCProvince	: true
			},
			pcaddr: {
				requiredCAddr		: true,
				minlength			: 5
			},
			pemployer:{
				minlength			: 5
			},
			pecountry: {
				requiredECountry	: true
			},
			peprovince: {
				requiredEProvince	: true
			},
			peaddr: {
				requiredEAddr		: true,
				minlength			: 5
			}
			
		},
		messages: {
			phschool: {
				requiredField 		: '',
				minlength			: hschool_minlength
			},
			phscountry: {
				requiredHsCountry	: hscountry_required
			},
			phsprovince: {
				requiredHsProvince	: hsprovince_required
			},
			phsaddr: {
				requiredHsAddr		: hsaddr_required,
				minlength			: hsaddr_minlength
			},
			pcollege: {
				minlength			: college_minlength
			},
			pccountry: {
				requiredCCountry	: ccountry_required
			},
			pcprovince: {
				requiredCProvince	: cprovince_required
			},
			pcaddr: {
				requiredCAddr		: caddr_required,
				minlength			: caddr_minlength
			},
			pemployer:{				
				minlength			: employer_minlength
			},
			pemployer:{				
				minlength			: employer_minlength
			},
			pecountry: {
				requiredECountry	: country_required
			},
			peprovince: {
				requiredEProvince	: province_required
			},
			peaddr: {
				requiredEAddr		: addr_required,
				minlength			: addr_minlength
			}			
		},
		errorPlacement: function(label, element) {			
			var id = element.attr('id');			
			label.insertAfter($('#' + id));				
		},
		submitHandler: function(form) {				
			form.submit();
		}
	});	
	$.validator.addMethod('requiredField', function() {		
		var strEmployer 	= $('#pemployer').val();
		var strECountry		= $('#pecountry').val();		
		var strEProvince	= $('#peprovince').val();
		if(strEProvince == undefined) strEProvince = '';
		var strEAddr		= $('#peaddr').val();
		if(strEAddr == undefined) strEAddr		= '';
		var strHschool		= $('#phschool').val();
		var strHsCountry	= $('#phscountry').val();
		var strHsProvince	= $('#phsprovince').val();
		if(strHsProvince == undefined) strHsProvince = '';
		var strHsAddr		= $('#phsaddr').val();
		if(strHsAddr == undefined) strHsAddr = '';
		var strCollege		= $('#pcollege').val();
		var strCCountry		= $('#pccountry').val();
		var strCProvince	= $('#pcprovince').val();
		if(strCProvince == undefined) strCProvince = '';
		var strCAddr		= $('#pcaddr').val();
		if(strCAddr == undefined) strCAddr = '';
		
		if(strEmployer == '' && strECountry == '' && strEProvince == '' && strEAddr == '' &&
			strHschool == '' && strHsCountry == '' && strHsProvince == '' && strHsAddr == '' && 
			strCollege == '' && strCCountry == '' && strCProvince == '' && strCAddr == '' 
		) {
			$('div.errorMessage').html(all_required);
			$('.error').show();					
			return false;
		}
		var intEWorking = $('.boxEduAndWorking').height();
		$('.boxHelp200').css('height',intEWorking + 'px');	
		$('.error').hide();
		return true;
	});
	$.validator.addMethod('requiredHsCountry', function(){
		var strHSchool		= $('#phschool').val();
		var strHsCountry	= $('#phscountry').val();
		if(strHSchool != '' && strHsCountry == '')
			return false;
		return true;
	});
	$.validator.addMethod('requiredHsProvince', function(){
		var strHSchool		= $('#phschool').val();
		var strHsProvince	= $('#phsprovince').val();
		if(strHSchool != '' && strHsProvince == '')
			return false;
		return true;
	});
	$.validator.addMethod('requiredHsAddr', function(){
		var strHSchool	= $('#phschool').val();
		var strHsAddr	= $('#phsaddr').val();
		if(strHSchool != '' && strHsAddr == '')
			return false;
		return true;
	});
	$.validator.addMethod('requiredCCountry', function(){
		var strCollege	= $('#pcollege').val();
		var strCCountry	= $('#pccountry').val();
		if(strCollege != '' && strCCountry == '')
			return false;
		return true;
	});
	$.validator.addMethod('requiredCProvince', function(){
		var strCollege		= $('#pcollege').val();
		var strCProvince	= $('#pcprovince').val();
		if(strCollege != '' && strCProvince == '')
			return false;
		return true;
	});
	$.validator.addMethod('requiredCAddr', function(){
		var strCollege	= $('#pcollege').val();
		var strCAddr	= $('#pcaddr').val();
		if(strCollege != '' && strCAddr == '')
			return false;
		return true;
	});
	$.validator.addMethod('requiredECountry', function() {		
		var strEmployer 	= $('#pemployer').val();
		var strECountry		= $('#pecountry').val();
		if(strEmployer != '' && strECountry == '')
			return false;
		return true;
	});
	$.validator.addMethod('requiredEProvince', function() {		
		var strEmployer 	= $('#pemployer').val();
		var strEProvince	= $('#peprovince').val();
		if(strEmployer != '' && strEProvince == '') {			
			return false;
		}
		return true;
	});
	$.validator.addMethod('requiredEAddr', function() {		
		var strEmployer 	= $('#pemployer').val();
		var strEAddr	= $('#peaddr').val();
		if(strEmployer != '' && strEAddr == '') {
			return false;
		}
		return true;
	});
	
});